home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-imgint.adb < prev    next >
Text File  |  1996-01-30  |  3KB  |  92 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                       S Y S T E M . I M G _ I N T                        --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.11 $                             --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. package body System.Img_Int is
  27.  
  28.    -------------------
  29.    -- Image_Integer --
  30.    -------------------
  31.  
  32.    function Image_Integer
  33.      (V    : Integer;
  34.       S    : access String)
  35.       return Natural
  36.    is
  37.       P : Natural;
  38.  
  39.    begin
  40.       if V >= 0 then
  41.          P := 1;
  42.          S (P) := ' ';
  43.       else
  44.          P := 0;
  45.       end if;
  46.  
  47.       Set_Image_Integer (V, S.all, P);
  48.       return P;
  49.    end Image_Integer;
  50.  
  51.    -----------------------
  52.    -- Set_Image_Integer --
  53.    -----------------------
  54.  
  55.    procedure Set_Image_Integer
  56.      (V  : Integer;
  57.       S  : out String;
  58.       P  : in out Natural)
  59.    is
  60.       procedure Set_Digits (T : Integer);
  61.       --  Set digits of absolute value of T, which is zero or negative. We work
  62.       --  with the negative of the value so that the largest negative number is
  63.       --  not a special case.
  64.  
  65.       procedure Set_Digits (T : Integer) is
  66.       begin
  67.          if T <= -10 then
  68.             Set_Digits (T / 10);
  69.             P := P + 1;
  70.             S (P) := Character'Val (48 - (T rem 10));
  71.  
  72.          else
  73.             P := P + 1;
  74.             S (P) := Character'Val (48 - T);
  75.          end if;
  76.       end Set_Digits;
  77.  
  78.    --  Start of processing for Set_Image_Integer
  79.  
  80.    begin
  81.       if V >= 0 then
  82.          Set_Digits (-V);
  83.  
  84.       else
  85.          P := P + 1;
  86.          S (P) := '-';
  87.          Set_Digits (V);
  88.       end if;
  89.    end Set_Image_Integer;
  90.  
  91. end System.Img_Int;
  92.